package com.kfpanda.search.batch.job;

import java.util.List;

import javax.annotation.Resource;

import org.apache.lucene.document.Document;
import org.springframework.batch.item.ItemWriter;

import com.kfpanda.search.index.Documentor;
import com.kfpanda.search.index.Indexer;

public class IndexWriter<T> implements ItemWriter<T>{
	
	@Resource(name="indexerImpl")
	private Indexer indexer;
	private String indexSaveDir;
	protected Documentor<T> documnetor;

	@Override
	public void write(List<? extends T> items) throws Exception {
		for(T t : items){
			Document doc = documnetor.document(t);
			indexer.indexCreate(indexSaveDir, doc);
		}
	}

	public Indexer getIndexer() {
		return indexer;
	}

	public void setIndexer(Indexer indexer) {
		this.indexer = indexer;
	}

	public Documentor<T> getDocumnetor() {
		return documnetor;
	}

	public void setDocumnetor(Documentor<T> documnetor) {
		this.documnetor = documnetor;
	}

	public String getIndexSaveDir() {
		return indexSaveDir;
	}

	public void setIndexSaveDir(String indexSaveDir) {
		this.indexSaveDir = indexSaveDir;
	}
	
}
